<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('修改项目')" />
    <th:block th:include="include :: datetimepicker-css" />
    <link rel="stylesheet" th:href="@{/css/myselect.css}"/>
    <style>
        body .layer-ext-moon .layui-layer-btn a{
            display: none;
        }
        .col-sm-8{
            height: 25px;
            line-height: 25px;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">

        <form class="form-horizontal m" id="form-project-edit" th:object="${lkProject}">
            <input name="proId" th:field="*{proId}" type="hidden">

            <div shiro:hasPermission="linkong:instructions:add" class="col-sm-1 col-md-offset-11">
                <button type="button" class="btn btn-w-m btn-primary" th:onclick="jumpAddInstructions([[*{proId}]] , [[*{proName}]])">添加批示</button>
            </div>

            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">所属企业：</label>
                    <div class="col-sm-8">
                        <span th:text="*{companyName}"></span>
                        <!--<input name="companyId" th:field="*{companyId}" class="form-control" type="text">-->
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">项目名称：</label>
                    <div class="col-sm-8">
                        <span th:text="*{proName}"></span>
                        <!--<input name="proName" th:field="*{proName}" class="form-control" type="text">-->
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">企业联系人：</label>
                    <div class="col-sm-8">
                        <span th:text="*{leader}"></span>
                            <!--<input name="leader" th:field="*{leader}" class="form-control" type="text">-->
                    </div>
                </div>
            </div>

            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">项目投资(万)：</label>
                    <div class="col-sm-8">
                        <span th:text="*{investmentAmount}"></span>
                        <!--<input name="investmentAmount" th:field="*{investmentAmount}" class="form-control" type="text" >-->
                    </div>
                </div>
            </div>



<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label">计划开始时间：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <div class="input-group date">-->
<!--                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
<!--                            <input name="startTime" th:value="${#dates.format(lkProject.startTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">移交日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <span th:text="${#dates.format(lkProject.transitionTime, 'yyyy-MM-dd')}"></span>
                            <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                            <!--<input name="transitionTime" th:value="${#dates.format(lkProject.transitionTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">时间节点：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <span th:text="${#dates.format(lkProject.startTime, 'yyyy-MM-dd')}"></span>
                            <span>---</span>
                            <span th:text="${#dates.format(lkProject.endTime, 'yyyy-MM-dd')}"></span>
                            <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                            <!--<input name="onlineTime" th:value="${#dates.format(lkProject.onlineTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" name="proTypeName" id="proTypeName">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">项目类型：</label>
                    <div class="col-sm-8">
                        <span th:each="dict:${@dict.getType('project_type')}"  th:if ="${lkProject.proType == dict.dictValue}"  th:text="${dict.dictLabel + ' '}" ></span>
                        <!--<select name="proType" id="proType" class="form-control m-b" th:with="type=${@dict.getType('project_type')}">-->
                            <!--<option value="">所有</option>-->
                            <!--<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${lkProject.proType == dict.dictValue}"></option>-->
                        <!--</select>-->
                    </div>
                </div>
            </div>
            <input name="proTag" id="proTag" class="form-control" type="hidden" th:field="*{proTag}">

<!--            <div class="col-sm-6" >-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label">项目状态：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <select name="proStage"  class="form-control m-b" th:with="type=${@dict.getType('project_stage')}">-->
<!--                            <option value="">所有</option>-->
<!--                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${lkProject.proStage == dict.dictValue}"></option>-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="col-sm-6" >
                <div class="form-group">
                    <label class="col-sm-4 control-label">简介：</label>
                    <div class="col-sm-8" >
                        <span th:text="${lkProject.remark}"></span>
                        <!--<textarea name="remark" class="form-control" th:text="${lkProject.remark}"></textarea>-->
                    </div>
                </div>
            </div>

            <!--<div class="col-sm-6" >-->
                <!--<div class="form-group">-->
                    <!--<label class="col-sm-4 control-label">项目标签：</label>-->
                    <!--<div class="col-sm-8">-->
                        <!--<div style="float: left;position: relative"></div>-->
                        <!--<div id="mySelect" class="mySelect" style="width: 260px;float: left"></div>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</div>-->
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">项目地址：</label>
                    <div class="col-sm-8">
                        <span th:text="${lkProject.proAddress}"></span>
                        <!--<input name="proAddress" id="proAddress" th:field="*{proAddress}" class="form-control" type="text" oninput="addressSearch()">-->
                    </div>
                </div>
            </div>
<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label"></label>-->
<!--                    -->
<!--                    <div class="col-sm-8">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->

            <div id="containerMap" style="width: 100%; height: 400px"></div>
            <input name="proLng" id="proLng" th:field="*{proLng}" class="form-control" type="hidden" >
            <input name="proLat" id="proLat" th:field="*{proLat}"  class="form-control" type="hidden" >
        </form>
    </div>
    <script th:inline="javascript">
        var datas = [[${@dict.getType('project_tag')}]];
        var proTag = [[${lkProject.proTag}]];
    </script>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=zaF87OcStYCRWUflA3U8IGA85PfV3MEO" ></script>
    <script th:src="@{/jade/js/select.js}"></script>
    <script type="text/javascript" >
        var prefix = ctx + "linkong/project";
        $("#form-project-edit").validate({
            focusCleanup: true
        });
        //
        // function submitHandler() {
        //     var proTypeName = $("#proType option:selected").text();
        //     var sqlTypeType= '[[${lkProject.proType}]]';
        //     var proType = $("#proType option:selected").val();
        //     if(proType != '' && !$.common.equals(sqlTypeType,proType)){
        //         $("#proTypeName").val(proTypeName);
        //     }
        //
        //     if ($.validate.form()) {
        //         $.operate.save(prefix + "/edit", $('#form-project-edit').serialize());
        //     }
        // }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        var map;
        map = new BMap.Map("containerMap",{enableMapClick:false});
        map.enableScrollWheelZoom();
        var proLng = $("input[name='proLng']").val();
        var proLat = $("input[name='proLat']").val();
        if ((proLng != null && proLng != "") && (proLat != null && proLat != "") ){
            var point = new BMap.Point(proLng != null ? proLng : 115.864,  proLat != null ? proLat : 28.689 );
            var marker = new BMap.Marker(new BMap.Point(proLng, proLat)); // 创建点
            map.addOverlay(marker);            //增加点
        }else{
            var point = new BMap.Point(115.864,28.689 );
        }
        map.centerAndZoom(point, 15);
        var geoc = new BMap.Geocoder();
        var local = new BMap.LocalSearch(map, {
            renderOptions:{map: map}
        });

        // 点击地图获取地址
        map.addEventListener("click", function(e){
            var pt = e.point;
            $("input[name='proLng']").val(e.point.lng)
            $("input[name='proLat']").val(e.point.lat)
            geoc.getLocation(pt, function(rs){
                var addComp = rs.addressComponents;
                $("input[name='proAddress']").val(addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber)
            });
        });
        // 搜索地址
        function addressSearch(){
            var address = $("input[name='proAddress']").val();
            local.search(address);
            geoc.getPoint(address, function(point){
                if (point) {
                    $("input[name='proLng']").val(point.lng)
                    $("input[name='proLat']").val(point.lat)
                }
            })
        }

        // 跳转批示添加
        function jumpAddInstructions(proId, proName){
            $.modal.open('批示',"/linkong/instructions/add/" + proId + "/" + proName, '900', ($(window).height() - 50));
        }


        function closeTab(index){
            layer.close(index);
        }


        $(function(){
            var _arr = [];
             if(proTag != null){
                _arr = proTag.split(",");
            }

            var dicList = [];
            $.each(datas, function(index, dict) {
                var obj = {};
                obj.label = dict.dictLabel;
                obj.value = dict.dictCode;
                dicList.push(obj);
                delete obj;
            });
            var mySelect= $("#mySelect").mySelect({
                mult:true,
                option:dicList,
                onChange:function(res){
                    var str = res.join(',');
                    $("#proTag").val(str);
                }
            });
            mySelect.setResult(_arr);
        })



    </script>
</body>
</html>